package luminus.origin.commands.rewrite

import luminus.origin.utils.Configurations.helper
import org.bukkit.event.player.PlayerCommandPreprocessEvent
import taboolib.common.platform.Awake
import taboolib.common.platform.event.SubscribeEvent
import taboolib.common.platform.function.adaptCommandSender
import taboolib.module.chat.component

object HelpOverwrite {
    @SubscribeEvent
    fun onCommand(event: PlayerCommandPreprocessEvent) {
        if (!helper.getBoolean("enable", true)) return
        val message = event.message
        if (message.startsWith("help") ||
            message.startsWith("?") ||
            message.startsWith("bukkit:help") ||
            message.startsWith("bukkit:?") ||
            message.startsWith("minecraft:?") ||
            message.startsWith("minecraft:help")) {
            event.isCancelled = true
            val h = helper.getStringList("helper")
            h.forEach {
                it.component().buildColored().sendTo(adaptCommandSender(event.player))
            }
        }
    }
}